package com.hhkj.admin.conf.service.biz.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.hhkj.admin.common.annotation.UseRedis;
import com.hhkj.admin.common.annotation.ClearRedis;
import com.hhkj.admin.common.event.DailyZeroHourTimeUpEvent;
import com.hhkj.admin.conf.common.cont.CommissionRateConst;
import com.hhkj.admin.conf.common.cont.ConfConst;
import com.hhkj.admin.conf.domain.*;
import com.hhkj.admin.conf.model.dopo.ConfDo;
import com.hhkj.admin.conf.model.dopo.ConfPo;
import com.hhkj.admin.conf.model.req.CommissionRateReq;
import com.hhkj.admin.conf.model.req.ConfReq;
import com.hhkj.admin.conf.model.req.ReceivingAccountReq;
import com.hhkj.admin.conf.model.req.WithdrawalLimitReq;
import com.hhkj.admin.conf.model.res.CommissionRateRes;
import com.hhkj.admin.conf.model.res.ConfRes;
import com.hhkj.admin.conf.model.res.ReceivingAccountRes;
import com.hhkj.admin.conf.model.res.WithdrawalLimitRes;
import com.hhkj.admin.conf.service.base.ConfService;
import com.hhkj.admin.conf.service.biz.ConfBizService;
import com.hhkj.admin.conf.service.biz.RuleBizService;
import com.hhkj.admin.conf.service.extend.ConfExtendService;
import com.ruoyi.common.base.biz.service.biz.BaseBizServiceImpl;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Service
public class ConfBizServiceImpl extends BaseBizServiceImpl<Conf, ConfReq, ConfRes, ConfDo, ConfPo, ConfService, ConfExtendService> implements ConfBizService {

    private List<RuleBizService> ruleBizServiceList;

    private Map<String, RuleBizService> ruleBizServiceMap = new HashMap<>();

    @Override
    public Map<String, Object> all() {
        HashMap<String, Object> ruleMap = new HashMap<>();
        ruleBizServiceList.forEach(ruleBizService -> {
            ConfConst.Code code = ruleBizService.getCode();
            ruleMap.put(code.getCode(), getConf(code));
        });
        return ruleMap;
    }

    @Override
    public <Res> Res getConf(ConfConst.Code code) {
        RuleBizService<Object, Res> ruleBizService = ruleBizServiceMap.get(code.getCode());
        Res res = ruleBizService.get();
        return res;
    }

    @Override
    public <Req> boolean updateConf(Req req, ConfConst.Code code) {
        RuleBizService<Req, Object> ruleBizService = ruleBizServiceMap.get(code.getCode());
        return ruleBizService.update(req);
    }

    @Autowired
    public void setRuleBizServiceList(List<RuleBizService> ruleBizServiceList) {
        this.ruleBizServiceList = ruleBizServiceList;
        ruleBizServiceList.forEach((ruleBizService -> {
            ruleBizServiceMap.put(ruleBizService.getCode().getCode(), ruleBizService);
        }));
    }
}
